<?php

/**
* xml-rpc params element wrapper
* @author J.Ducastel <fredbird@fredbird.org>
* @version
*/
class ooXmlRpcParams {
/*------------------------------------------------------------------------------
                                                                     constructor
------------------------------------------------------------------------------*/
    /**
    *
    * @access
    * /
    function ooXmlRpcParams() {
        $this->__construct();
    }/**/

    /**
    *
    * @access
    * /
    function __construct() {

    }/**/
/*------------------------------------------------------------------------------
                                                                  public methods
------------------------------------------------------------------------------*/
    /**
    * sets value(s) from node
    * @param ooXmlRpcNode &$node
    * @access public
    * @return bool
    */
    function setFromNode(&$node) {
        if (!is_a($node,'ooxmlrpcdomnode')) {
            return false;
        }
        //var_dump($node);
        // searching for values
        if ($vNodes=$node->getxpathnodes('child::param/value')) {
            for ($n=0; $n<count($vNodes); $n++) {
                $value=&new ooXmlRpcValue();
                //$vNode=&new ooXmlRpcDomNode($valueNodes[$n]);
                $value->setFromNode($vNodes[$n]);
                $this->values[]=&$value;
            }
        }
        return true;
    }/**/

    /**
    * build and appends self node(s) to parent node
    * @param
    * @access public
    * @return bool
    */
    function appendToNode(&$parentNode) {
        // build & append self
        $selfNode=&$parentNode->makeChild('params');
        // build & append values to self
        for ($n=0; $n<count($this->values); $n++) {
            $paramNode=$selfNode->makeChild('param');
            $this->values[$n]->appendToNode($paramNode);
        }
        return true;
    }/**/

    /**
    * sets a param's value
    * @param ooXMlRpcValue|mixed $value either ooXmlRpcValue instance, or php var
    * @param int $index param index, if ommitted will be instered at end of array
    * @access public
    * @return bool
    */
    function setParam($value,$index=null) {
        // building value instance if necessary
        if (!is_a($value,'ooXmlRpcValue')) {
            $valueO=new ooXmlRpcValue();
            if (!$valueO->setValue($value))
                return false;
            $value=&$valueO;
        }
        if (is_int($index))
            $this->values[$index]=$value;
        else
            $this->values[]=&$value;
        return true;
    }/**/

    /**
    * return values as an array of php vars
    * @access public
    * @return array
    */
    function & getValues() {
        $values=array();
        for ($n=0; $n<count($this->values); $n++)
            $values[]=$this->values[$n]->getValue();
        return $values;
    }/**/

    /**
    *
    * @param
    * @access public
    * @return ooXmlRpcValue
    */
    function & getParam($index) {
        $r=false;
        if (isset($this->values[$index]))
            $r=$this->values[$index];
        return $r;
    }/**/

    /**
    *
    * @param
    * @access public
    * @return
    * /
    function () {

    }/**/
/*------------------------------------------------------------------------------
                                                                      properties
------------------------------------------------------------------------------*/
    /**
    * @var type desc
    */
    var $values=array();
}
?>
